﻿using System;
using System.Collections.Generic;
using Microsoft.FxCop.Sdk;

namespace LINQtoFxCop.Core
{
  public class Namespace : Node
  {
    private readonly Identifier _name;
    private readonly IList<TypeNode> _types;

    public Namespace(Identifier name)
      : base(NodeType.Namespace)
    {
      _name = name;
      _types = new List<TypeNode>();
    }

    public void Add(TypeNode type)
    {
      if (type.Namespace.UniqueIdKey == _name.UniqueIdKey)
        _types.Add(type);
      else
        throw new ArgumentException("Type does not belong to this namespace", "type");
    }

    public IEnumerable<TypeNode> Types
    {
      get { return _types; }
    }

    public override int UniqueKey
    {
      get
      {
        return _name.UniqueIdKey;
      }
    }
    public override string ToString()
    {
      return _name.Name;
    }
  }
}
